[20260325] BOJ / P1 / Railway / 권혁준#2044
Merged
ShinHeeEul merged 1 commit intomainfrom Mar 25, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/22197
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
정점이 N개이고, 간선에 가중치가 있는 트리에 M개의 쿼리가 주어진다.
처음에 모든 간선의 가중치는 0이다.
하나의 쿼리는 다음과 같이 구성된다.
모든 쿼리가 끝난 후, 간선의 가중치가 K 이상인 것들을 모두 출력해보자.
🔍 풀이 방법
루트를 1로 정한다.
쿼리를 하나만 처리한다고 가정하면, 아래 과정으로 쿼리를 처리할 수 있다.
쿼리를 여러 개 처리해야 하지만, 위 방법을 응용해서 모든 점에 쿼리의 번호를 기록해두는 Map을 관리하는 방식을 고려해봤다.
자식들의 Map을 부모의 Map으로 합칠 때는,
작은 크기의 맵을 큰 크기의 맵에 합치면 전체 시간복잡도가 모든 정점 집합의 크기 합 X에 대해 O(XlogX)로 떨어진다.
⏳ 회고
다른 풀이도 있는 것 같은데 더 알아봐야겠다